﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Md.Demo.Rpc
{
    public static class ServiceRegistered
    {
        public static IServiceCollection ServerRegistered(this IServiceCollection service)
        {
            var dataAccessTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Name.EndsWith("Rpc")).ToList();
            dataAccessTypes.ForEach(t => service.AddTransient(t));
            return service;
        }
        public static IServiceCollection RpcRegistered(this IServiceCollection service, IConfiguration configuration)
        {
            service.AddGrpcClient<Md.Demo.Service.Greeter.GreeterClient>(o =>
            {
                o.Address = new Uri(configuration.GetSection("RpcUrl:Greeter").Value);
            });

            service.AddGrpcClient<Md.Demo.Service.Interview.InterviewClient>(o =>
            {
                o.Address = new Uri(configuration.GetSection("RpcUrl:Greeter").Value);
            });
            return service;
        }
    }
}
